package com.qy139.picture.controller;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qy139.entity.Picture;
import com.qy139.entity.Store;
import com.qy139.picture.service.IPictureService;
import com.qy139.util.Result;
import org.apache.commons.io.FileUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yuhaochen
 * @since 2021-11-30
 */
@RestController
@RequestMapping("/picture")
public class PictureController {
    @Resource
    private IPictureService pictureService;
    /*分页+模糊查询所有图片路径*/
    @GetMapping("/findAllPic")
    public Result findAllPic(Page page, Picture picture){
        QueryWrapper<Picture> queryWrapper = new QueryWrapper();
        queryWrapper.like("url",picture.getUrl());
        Page page1 = pictureService.page(page,queryWrapper);
        return new Result(page1);
    }

    /*展示图片*/
    @GetMapping("/findStoreImg/{imgid}")
    public Result findStoreImg(@PathVariable String imgid){
        List<Picture> list=pictureService.listByImgs(imgid);
        return new Result(list);
    }

    /*修改 逻辑删除*/
    @PutMapping("/updatePic")
    public Result updPic(@RequestBody Picture picture){
        picture.setUpdatetime(new Date());
        return new Result(pictureService.saveOrUpdate(picture));
    }
    /*修改状态*/
    @PutMapping("/updateStu")
    public Result updateStu(@RequestBody Picture picture){
        //System.out.println("图片的信息："+picture);
        return new Result(pictureService.updateStu(picture));
    }

    /*阿里云文件上传*/
    @PostMapping("/uploadImg")
    @ResponseBody
    public Result upload3(@RequestParam("file") MultipartFile[] file, Picture picture) throws IOException {
        List<Map> list=pictureService.uploadFile(file,picture);
        return new Result(list);
    }
}

